<?php

use Illuminate\Support\Facades\Route;
use magein\laravel\seecms\Dispatch;
use magein\laravel\seecms\middleware\AuthorizationMiddleware;
use magein\laravel\seecms\middleware\IsLoginMiddleware;
use magein\laravel\seecms\middleware\PermissionMiddleware;
use magein\seecms\controller\User;

$callable = function () {
    # 快捷登录路由
    Route::any('/', [User::class, 'index'])->middleware([IsLoginMiddleware::class]);
    Route::any('/login', [User::class, 'index'])->middleware([IsLoginMiddleware::class]);

    // 用户登录
    Route::prefix('user')->middleware([IsLoginMiddleware::class])->group(function () {
        Route::get('/', [User::class, 'index']);
        Route::get('index', [User::class, 'index']);
    });

    // 修改首页
    //Route::any('s/home/main', '\app\admin\controller\Main@index');

    // 不需要验证是否登录、权限的用户登录、登出、无权限页面路由
    Route::any('/u/{controller}/{action}', [Dispatch::class, 'controller']);

    // 系统控制器路由
    Route::any('/s/{controller}/{action}', [Dispatch::class, 'controller'])
        ->middleware([AuthorizationMiddleware::class, PermissionMiddleware::class]);
    // 构建页面路由
    Route::any('/p/{name}/page', [Dispatch::class, 'resource'])
        ->middleware([AuthorizationMiddleware::class]);

    // 页面资源路由
    Route::any('/p/{name}/{action}', [Dispatch::class, 'resource'])
        ->middleware([AuthorizationMiddleware::class, PermissionMiddleware::class]);
};

Route::prefix('admin')->group($callable);
